#ifndef PARSER_H
#define PARSER_H
#include <stdio.h>
#include "event.h"

typedef struct Parser {
    FILE* f;
    void *opaque;
    int (*parse) (void *opaque, FILE *in, Event *e);
    void (*destructor) (void *opaque);
} Parser;

#define PARSER_INCOMING 0
#define PARSER_ERR -1
#define PARSER_END 1

static inline int parser_parse (Parser *p, Event *e) {
    return p->parse (p->opaque, p->f, e);
}

Parser *parser_create (void *opaque,void(*destructor)(void*), FILE* in);

static inline void parser_destructor (Parser *p) {
    p->destructor (p->opaque);
}

Parser *optc_parser_create (FILE *in);

#endif